(function(){

	//验证开始时间必须小于结束时间
	Ext.apply(Ext.form.VTypes, {
        daterange : function(val, field) {
            var date = field.parseDate(val);
            if (!date) {
                return;
            }
            if (field.cascadeFatherCom && (!this.dateRangeMax || (date.getTime() != this.dateRangeMax.getTime()))) {
                var cascadeFatherComArray = Ext.ComponentQuery.query('datefieldcascade[name='+field.cascadeFatherCom+']');
				if(cascadeFatherComArray.length>0){
					var cascadeFatherCom = cascadeFatherComArray[0];
					cascadeFatherCom.setMaxValue(date);
//                	cascadeFatherCom.validate();
				}
                this.dateRangeMax = date;
            } else if (field.cascadeChildCom && (!this.dateRangeMin || (date.getTime() != this.dateRangeMin.getTime()))) {
                var cascadeChildComArray = Ext.ComponentQuery.query('datefieldcascade[name='+field.cascadeChildCom+']');
				if(cascadeChildComArray.length>0){
					var cascadeChildCom = cascadeChildComArray[0];
					cascadeChildCom.setMinValue(date);
//					cascadeChildCom.validate();
				}
                this.dateRangeMin = date;
            }
            return true;
        }
    });
	
	/**
	 * 日期级联
	 * @author zoe
	 * 用法：
	 * {
			xtype:'datefieldcascade',
			anchor: '100%',
			cascadeChildCom:'child',
	        fieldLabel: 'father',
	        labelWidth:40,
	        name: 'father'
		},
		{
			xtype:'datefieldcascade',
			anchor: '100%',
			cascadeFatherCom:'father',
	        fieldLabel: 'child',
	        labelWidth:40,
	        name: 'child'
		}
	 */
	Ext.define('App.view.extend.date.DateFieldCascade',{
		extend:'Ext.form.field.Date',
		alias:'widget.datefieldcascade',
		editable:false,
		format:'Y-m-d',
		cascadeFatherCom:null,//级联父对象
		cascadeChildCom:null,//级联子对象
		vtype:'daterange',
		initCompanent:function(){
			this.callParent(arguments);
		}		
	})
})()